package com.lj.admin.controller.system;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.lj.common.core.ajax.Result;
import com.lj.common.core.controller.BaseController;
import com.lj.common.core.model.system.SysDictData;
import com.lj.system.service.ISysDictDataService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 数据字典前端控制器
 *
 * @author 小李飞刀
 */
@RequestMapping("/system/dict/data")
@RestController
public class SysDictDataController extends BaseController {

    @Resource
    private ISysDictDataService dictDataService;

    /**
     * 根据字典类型查询字典数据信息
     */
    @GetMapping(value = "/type/{dictType}")
    public Result dictType(@PathVariable String dictType) {
        List<SysDictData> data = dictDataService.selectDictDataByType(dictType);
        if (ObjectUtil.isNull(data)) {
            data = CollUtil.newArrayList();
        }
        return Result.success(data);
    }
}
